import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import Keys

# 七月 业务流程 一
driver=webdriver.Edge()
driver.maximize_window()
driver.get('http://10.59.9.12:7001/')

# 隐式等待 2
driver.implicitly_wait(1)
# 第一步  登录   鼠标单击
sbdj=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
# 强制等待 1
time.sleep(5)
# 单击
ActionChains(driver).click(sbdj).perform()
# 双击
# ActionChains(driver).double_click(sbdj).perform()
# 第二步  用户名   username
a=driver.find_element(By.NAME,'username')
a.send_keys('13811033962')
# 键盘事件
a.send_keys(Keys.ENTER)
time.sleep(3)
# 第三步  密码   password
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(8)
# 第四步  登录按钮  finish-btn
# 显示等待 3
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'finish-btn'))).click()
#切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(10)
# 点击首页商品列表搜索
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(3)
# 滑动
driver.execute_script('window.scrollTo(0,800)')
time.sleep(5)
# 商品详情  /html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img
driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img').click()
time.sleep(3)
# 立即购买
driver.find_element(By.ID,'buy-cart').click()
time.sleep(3)
# 创建订单并支付  ask-btn
driver.find_element(By.CSS_SELECTOR,'.ask-btn').click()
time.sleep(3)
# 确认地址
driver.find_element(By.XPATH,'//input[starts-with(@id,"address-801")]').click()
time.sleep(3)
# 下一步
driver.find_element(By.XPATH,'//*[@id="order-button"]').click()
time.sleep(3)
# 退出
driver.close()



#
# # 打印元素属性值
# yuansu=driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img')
# # 打印文本值
# print(yuansu.text)
# # 获取元素具体属性
# print(yuansu.get_attribute('class'))
# # 获取元素宽值
# print(yuansu.size)
# # 获取元素坐标
# print(yuansu.location)
# # 打印元素是否可用
# print(yuansu.is_enabled())

# 打印元素是否显示
# print(yuansu.is_selected())
# # 是否选中
# print(yuansu.is_selected())